﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Projektet.View
{
    static class Camera
    {
        private static int _resolutionX;
        private static int _resolutionY;

        private static float _scrollOffset = 0;
        private static float _heightOffset = 720;

        public static Vector2 Resolution 
        {
            get { return new Vector2(_resolutionX, _resolutionY); }
            set 
            {
                _resolutionX = (int)value.X;
                _resolutionY = (int)value.Y;
            }
        }

        //public Camera(int resX, int resY) 
        //{
        //    _resolutionX = resX;
        //    _resolutionY = resY;
        //}

        public static Vector2 GetVisualVector(Vector2 logicalCoords)
        {
            int scaleX = _resolutionX / 100;
            int scaleY = _resolutionY / 100;

            //Vector2 visualCoords = new Vector2(logicalCoords.X * scaleX - _scrollOffset, logicalCoords.Y * scaleY + _heightOffset);
            Vector2 visualCoords = new Vector2(logicalCoords.X * scaleX, logicalCoords.Y * scaleY);
            return visualCoords;
        }

        public static Vector2 GetVisualVectorWithOffset(Vector2 logicalCoords)
        {
            int scaleX = _resolutionX / 100;
            int scaleY = _resolutionY / 100;

            //Vector2 visualCoords = new Vector2(logicalCoords.X * scaleX - _scrollOffset, logicalCoords.Y * scaleY + _heightOffset);
            Vector2 visualCoords = new Vector2(logicalCoords.X * scaleX - _scrollOffset, logicalCoords.Y * scaleY);
            return visualCoords;
        }

        public static Vector2 GetLogicalVector(Vector2 visualCoords) 
        {
            Vector2 logicalCoords = new Vector2(visualCoords.X, visualCoords.Y);
            return logicalCoords;
        }

        public static Rectangle GetVisualRectangle(Rectangle logicalRect) 
        {
            int scaleX = _resolutionX / 100;
            int scaleY = _resolutionY / 100;
            
            Rectangle visualRect = new Rectangle(
                (logicalRect.X - (int)_scrollOffset) * scaleX,
                (logicalRect.Y - logicalRect.Height * scaleY) + (int)_heightOffset,
                logicalRect.Width * scaleX,
                logicalRect.Height * scaleY);

            return visualRect;
        }

        public static Rectangle GetVisualRectangleNoOffset(Rectangle logicalRect)
        {
            int scaleX = _resolutionX / 100;
            int scaleY = _resolutionY / 100;

            Rectangle visualRect = new Rectangle(
                logicalRect.X * scaleX,
                (logicalRect.Y  * scaleY),
                logicalRect.Width * scaleX,
                logicalRect.Height * scaleY);

            return visualRect;
        }

        public static int GetVisualOffset() 
        {
            return (int)(_scrollOffset * (_resolutionX / 100));
        }

        public static void IncreaseOffset()
        {
            if(_scrollOffset <= 100)
            {
                _scrollOffset++;
            }
        }

        public static void DecreaseOffset()
        {
            if (_scrollOffset >= 0)
            {
                _scrollOffset--;
            }
        }
    }
}
